<?php
// 主页
namespace Admin\Controller;

use Org\Net\UpYun;
use Think\Controller;
use Org\Net\UploadFile;
use Admin\Model\ArticleModel;
use Admin\Model\CategoryModel;
use Admin\Model\SiteModel;
use Admin\Model\TopicModel;

class IndexController extends CommonController {
	public function index() {
		$category = new CategoryModel ();
		$where = 'type="site"';
		$data ['title'] = '小站管理';
		$data ['SiteCategory'] = $category->search ( $where );
		$this->data = $data;
		$this->display ();
	}
	public function topic() {
		$data ['nav'] = 'topic';
		$do = I ( 'get.do' );
		$id = I ( 'get.id' );
		$page = I ( 'get.p' );
		$topic = new TopicModel ();
		if ($do == 'save') {
			$rs = $topic->saveData ( $_POST, $_POST ['id'] );
			if ($rs ['status']) {
				$this->success ( $rs ['msg'] );
			} else {
				$this->error ( $rs ['msg'] );
			}
			exit ();
		}elseif($do =='delete'){
			$rs = $topic->delete($id);
			if ($rs ['status']) {
				$this->success ( $rs ['msg'] ,'/admin.php?m=Admin&c=Index&a=topic');
			} else {
				$this->error ( $rs ['msg'] );
			}
			exit();
		} elseif ($id) {
			$data ['info'] = $topic->getInfo ( $id );
		} else {
			$where = 1;
			$data ['topic'] = $topic->search ( $where, $page, ' updatetime desc' );
		}
		$data ['do'] = $do;
		$data ['title'] = '专题管理';
		$this->data = $data;
		$this->display ();;
	}
	public function article() {
		$data ['nav'] = 'article';
		$do = I ( 'get.do' );
		$id = I ( 'get.id' );
		$page = I ( 'get.p' );
		$article = new ArticleModel ();
		if ($do == 'save') {
			$rs = $article->saveData ( $_POST, $_POST ['id'] );
			if ($rs ['status']) {
				$this->success ( $rs ['info'] );
			} else {
				$this->error ( $rs ['info'] );
			}
			exit ();
		} elseif ($id) {
			$category = new CategoryModel ();
			$where = 'type="article"';
			$data ['category'] = $category->search ( $where );
			$data ['info'] = $article->getInfo ( $id );
		} else {
			$category = new CategoryModel ();
			$where = 'type="article"';
			$data ['category'] = $category->search ( $where );
			$where = 1;
			$data ['article'] = $article->search ( $where, $page, ' updatetime desc' );
		}
		$data ['do'] = $do;
		$data ['title'] = '文章管理';
		$this->data = $data;
		$this->display ();
	}
	public function siteedit() {
		$site = new SiteModel ();
		$id = $_REQUEST ['id'];
		$data ['site'] ['info'] = $site->getInfo ( $id );
		$data ['title'] = '编辑小站';
		$this->data = $data;
		$this->display ();
	}
}